package org.grails.simplesolr

import org.apache.solr.client.solrj.response.QueryResponse;

class SimpleSolrQueryResponse {
	QueryResponse response
	
	def getObjectList () {
		def res = []
		def previousType = ""
		def gclass
		
		response.getResults().each { doc ->
			String type = doc.getFieldValue("doctype_s")
			String sid = doc.getFieldValue("id")
			int id = sid.substring(sid.lastIndexOf('-') + 1) as int
			if (type != previousType) {
				previousType = type
				gclass = ApplicationHolder.application.getClassLoader().loadClass(type)
			}
			
			res << gclass.get(id)
		}
		return res
	}
}
